package com.mall.order.biz.handler;

import com.mall.order.mq.order.DelayOrderProducer;
import com.mall.order.biz.context.CreateOrderContext;
import com.mall.order.biz.context.TransHandlerContext;
import com.mall.order.mq.order.DelayOrderProducerReminder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 利用mq发送延迟取消订单消息
 * @Date: 2019-09-17 23:14
 **/
@Component
@Slf4j
public class SendMessageHandler extends AbstractTransHandler {

	@Autowired
	DelayOrderProducer delayOrderProducer;

	@Autowired
	DelayOrderProducerReminder producerReminder;

	@Override
	public boolean isAsync() {
		return false;
	}

	/*
	 * @description: 用消息队列延时发送消息，判断订单状态是否为已支付
	 * @return: boolean
	 * @author: mabinbin
	 * @date: 2021/8/26
	 */
	@Override
	public boolean handle(TransHandlerContext context) {
		CreateOrderContext orderContext = (CreateOrderContext) context;
		String orderId = orderContext.getOrderId();

		//发送延时消息
		boolean sendResult = delayOrderProducer.sendOrderDelayMessage(orderId,5);
		boolean orderReminder = producerReminder.sendMessage(orderId, "orderReminder", 3);
		return sendResult & orderReminder;
	}
}